Skip to content

fix: link invalid uploads to fallback group (#108)#113

Merged
agent-p1p merged 2 commits into
masterfrom
pip/goggles-108
Jun 24, 2026
Merged

fix: link invalid uploads to fallback group (#108)#113
agent-p1p merged 2 commits into
masterfrom
pip/goggles-108

Conversation

@agent-p1p

@agent-p1p agent-p1p commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • persist the fallback AuditGroup on AuditFile.groups for wholesale-quarantined uploads
  • add a regression test for invalid UTF-8 uploads sent to a group endpoint
  • verify the API response and group file listing both expose the fallback group

Test Plan

  • RED: DJANGO_DEBUG=1 uv run python manage.py test forensics.tests.AuditLogIngestionTests.test_invalid_utf8_group_upload_links_file_to_fallback_group -v 2 failed with None != 'mobile-qa'
  • GREEN: DJANGO_DEBUG=1 uv run python manage.py test forensics.tests.AuditLogIngestionTests.test_invalid_utf8_group_upload_links_file_to_fallback_group -v 2
  • DJANGO_DEBUG=1 uv run python manage.py test forensics.tests.AuditLogIngestionTests.test_invalid_utf8_group_upload_links_file_to_fallback_group forensics.tests.AuditLogIngestionTests.test_invalid_utf8_upload_file_sha256_race_returns_existing_audit_file forensics.tests.AuditLogIngestionTests.test_absent_group_ref_with_fallback_group_still_uses_fallback forensics.tests.AuditLogIngestionTests.test_non_string_group_ref_with_fallback_group_is_not_rebucketed forensics.tests.AuditLogIngestionTests.test_malformed_string_group_ref_with_fallback_group_is_not_rebucketed -v 2
  • DJANGO_DEBUG=1 uv run python manage.py test
  • DJANGO_DEBUG=1 uv run python manage.py check
  • uv run ruff check .
  • uv run ruff format --check .
  • DJANGO_DEBUG=1 uv run python manage.py makemigrations --check --dry-run

Closes #108


Open in Stage

@stage-review

stage-review Bot commented Jun 24, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 2 individual chapters for you:

Title
1 Link invalid uploads to fallback AuditGroup
2 Verify fallback group linking in tests
Open in Stage

Chapters generated by Stage for commit 4df2e9f on Jun 24, 2026 6:29am UTC.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@agent-p1p, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 37 minutes and 19 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26261b68-7eaa-42a4-ab24-44c524c4595b

📥 Commits

Reviewing files that changed from the base of the PR and between 2591fe7 and 4df2e9f.

📒 Files selected for processing (2)
  • forensics/ingest.py
  • forensics/tests.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pip/goggles-108

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@agent-p1p agent-p1p left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pip adversarial review — PR #113 (goggles#108)

Verdict: APPROVE — 0 blocking, 1 suggestion, 2 nitpicks.

The fix is correct, minimal, and exactly mirrors the prescribed remedy and the create_events() precedent: a single audit_file.groups.add(fallback_group) inside the transaction.atomic() block, guarded by fallback_group is not None, alongside the existing updated_at bump. Wholesale-quarantined uploads now appear in groups_for_audit_file (API response + detail page), audit_files_for_group (Files tab), and the group file_count. groups.add is idempotent, so the fallback_group is None path and the dedup races are unaffected. All 156 forensics tests pass. The regression test meaningfully exercises both helper paths and the API group/groups shape on the real non-UTF-8 byte path. No security/privacy regression — linking only attaches the file to the same fallback group its FK already pointed at, and nothing sensitive is logged.

🔴 BLOCKING

none

💡 SUGGESTION

  • except Exception quarantine path is uncovered for the M2M linkforensics/ingest.py:323-325. save_invalid_upload has two callers: the non-UTF-8 decode path (ingest.py:159) and the defense-in-depth except Exception quarantine (ingest.py:251). The new test (tests.py:1097) exercises only the non-UTF-8 path. The existing except Exception test (test_unexpected_ingest_error_quarantines_upload_not_500, tests.py:2118) posts to the no-group endpoint, so fallback_group is None and the new groups.add branch is never hit there. Consider a quarantine-path upload to a group endpoint asserting the fallback-group link, since #108 names both as in-scope. (Same code line is shared, so this is coverage, not correctness.)

🔧 NITPICK

  • Dedup early-returns still skip the M2M linkforensics/ingest.py:289-291 and 327-329. Re-uploading identical invalid bytes with a different fallback group than the original returns created=False and never adds the new group. This is pre-existing, matches the valid path's identical behavior (ingest.py:178-180), is keyed on file-content hash (arguably correct dedup semantics), and is out of scope for #108. Flagging only so it's an explicit, conscious non-goal. No change requested.
  • groups_for_audit_file(...) == [fallback_group] assertion relies on pk-based __eq__forensics/tests.py:1117-1118. The annotated audit_files_for_group row equals the plain instance via Django pk comparison; works and is fine, just non-obvious.

Sensitive paths touched: none.


Adversarial review delegated to Cursor CLI (claude-opus-4-8-xhigh), findings verified independently against the checked-out branch. CI: Django tests pending; pip-audit pass; CodeRabbit rate-limited (no findings).

@agent-p1p

Copy link
Copy Markdown
Contributor Author

Address-review update: rebased onto current master and addressed the adversarial review suggestion with test_unexpected_ingest_error_group_upload_links_file_to_fallback_group, covering the except Exception quarantine path through the group upload endpoint. Local gates pass and GitHub checks are green.

@agent-p1p agent-p1p marked this pull request as ready for review June 24, 2026 06:31
@agent-p1p agent-p1p merged commit 3abf2cc into master Jun 24, 2026
3 checks passed
@agent-p1p agent-p1p deleted the pip/goggles-108 branch June 24, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

save_invalid_upload() never records the file→group M2M link, so wholesale-quarantined uploads vanish from their fallback group (partial #37 gap)

1 participant